package fhp.hlhj.giantfold.adapter

import android.graphics.Color
import android.os.Parcel
import android.os.Parcelable
import android.text.SpannableStringBuilder
import android.text.Spanned
import android.widget.ImageView
import android.widget.TextView
import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import fhp.hlhj.giantfold.R
import fhp.hlhj.giantfold.customView.FlipDialog
import fhp.hlhj.giantfold.customView.ShareDialog
import fhp.hlhj.giantfold.javaBean.SelfOrderBean
import android.text.Spanned.SPAN_INCLUSIVE_EXCLUSIVE
import android.text.style.ForegroundColorSpan


/**
 * author: FHP
 * data: on 2018\1\25 0025 16:59
 * E-Mail: 103945089@qq.com
 */
class SelfOrderAdp(layoutId:Int,datas:List<SelfOrderBean.DataBean>) :BaseQuickAdapter<SelfOrderBean.DataBean,BaseViewHolder>(layoutId,datas), FlipDialog.OnFinishFlip {
    override fun convert(helper: BaseViewHolder, item: SelfOrderBean.DataBean?) {
        helper.setText(R.id.itemTitle,item?.product_name)
        helper.setText(R.id.orderPrice,"订单金额${item?.actual_amount}")
        helper.setText(R.id.itemPrice,item?.actual_amount)
        helper.setText(R.id.itemTime,item?.created_time?.split(" ")!![0])
        val tittle = helper.getView<TextView>(R.id.itemTitle)
        val span = SpannableStringBuilder("缩进" + tittle.getText())
        span.setSpan(ForegroundColorSpan(Color.TRANSPARENT), 0, 2,
                Spanned.SPAN_INCLUSIVE_EXCLUSIVE)
        tittle.setText(span)
        val btNext = helper.getView<ImageView>(R.id.btNext)
        when(item?.b_type){
            "taobao"->{
                helper.setImageResource(R.id.imgType,R.mipmap.quanbudingdan_taobao)
            }
            "jd"->{
                helper.setImageResource(R.id.imgType,R.mipmap.quanbudingdan_taobao)

            }
            "xrhb"->{

            }
            "fy"->{

            }
            "xp"->{
                helper.setImageResource(R.id.imgType,R.mipmap.xiaopiao)
            }
        }

        when(item?.fanpai_status){
            "0"->{
                btNext.setOnClickListener {
                    val flipDialog = FlipDialog(mContext, item.id,this)
                    flipDialog.show()
                }
                btNext.setImageResource(R.mipmap.wodedingdan_fanpai_fp)
            }
            "1"->{
                btNext.setImageResource(R.mipmap.wo_quanbudingdan_fanpai)
                btNext.setOnClickListener {
                    ShareDialog(mContext,item.id).show()
                }
            }
            "2"->{

            }
        }

        if (item?.product_name.equals("新人红包")){
            Glide.with(mContext).load(R.mipmap.nianhuashouyi_hb).asBitmap().dontAnimate().placeholder(R.mipmap.exp5).into(helper.getView(R.id.icon))
        }else{
            if (item?.tkjd_sp.equals("1")){
                Glide.with(mContext).load(item?.product_pic_url).asBitmap().dontAnimate().placeholder(R.mipmap.exp5).into(helper.getView(R.id.icon))
            }else{
                Glide.with(mContext).load(item?.pict_url).asBitmap().dontAnimate().placeholder(R.mipmap.exp7).into(helper.getView(R.id.icon))
            }
        }

    }

    override fun onfinish() {
        notifyDataSetChanged()
    }
}